package org.global;

import lombok.*;

import java.util.List;


@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {
    private String msg;
    private Integer code;
    private Object body;

    public static AjaxResult error() {
        return AjaxResult.builder().code(500).msg("系统异常。").build();
    }

    public static AjaxResult ok(Object obj) {
        return AjaxResult.builder().code(200).body(obj).build();
    }

    public static AjaxResult ok(Object obj, String msg) {
        return AjaxResult.builder().code(200).body(obj).msg(msg).build();
    }

    public static AjaxResult define(int code, String msg) {
        return AjaxResult.builder().code(code).msg(msg).build();
    }

    public static AjaxResult error(List<Exception> exceptions) {
        StringBuilder builder = new StringBuilder();
        for (Exception e : exceptions) {
            builder.append(e.getMessage()).append("，");
        }
        return AjaxResult.builder().msg(builder.toString()).code(500).build();
    }
}
